<?php

class Passcode extends AppModel {

  public $name = 'passcode';
  public $validate = array(
    'id' => array(
        'required' => array(
            'rule' => 'notEmpty',
            'required' => true,
            'message' => 'Passcode is required'
        ),
        'valid' => array(
            'rule' => array('isValidPasscode'),
            'message' => 'This is not a valid passcode'
        )
    )
  );

  function isValidPasscode($field) {
    $retVal = false;
    if (!empty($field)) {
      $passcode = new Passcode();
      $result = $passcode->find("first", array('conditions' => array("passcode.id" => $this->data['Passcode']['id'])));
      $retVal = empty($result) ? false : true;
    }
    return $retVal;
  }

}

?>
